package top.houry.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;

@RestController
public class Test {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    /**
     * redis生产者测试
     *
     * @return
     */
    @GetMapping("/publish")
    public void publish(@RequestParam(value = "channel") String channel) {
        while (true) {
            try {
                TimeUnit.MILLISECONDS.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            redisTemplate.convertAndSend(channel, String.valueOf(System.currentTimeMillis()));
        }

    }

    public static void main(String[] args) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
        System.out.println(String.format("user:sign:%d:%s", 195847L, LocalDate.now().format(formatter)));
        System.out.println(LocalDate.now().getDayOfMonth() - 1);
    }


}
